using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WP.Commons;
using WP.DB;
using WP.Modules;
namespace WP.Modules
{
    public partial class frmInquiry : BaseQryRpt 
    {
        #region ***Define Variable

        DBAccess dBAccess = null;
        private string m_strTableName = string.Empty;
        public string TableName
        {
            get
            {
                return m_strTableName;
            }
            set
            {
                m_strTableName = value;
            }
        }


        #endregion Define Variable***

        #region ***Constructor Functions
        public frmInquiry()
        {
            InitializeComponent();
            LoadAllControl(new ArrayList(this.Controls));
            this.MinimumSize = this.Size;
        }
        #endregion Constructor Functions***

        #region ***Form Functions
        public void ShowData(DBAccess dBAccess, DataTable dtData)
        {
            ShowData(dBAccess, dtData, string.Empty, false, string.Empty);
        }
        public void ShowData(DBAccess dBAccess, DataTable dtData, string strColWidth, bool bNeedPrint)
        {
            ShowData(dBAccess, dtData, strColWidth, bNeedPrint, string.Empty);
        }
        public void ShowData(DBAccess dBAccess, DataTable dtData, string strColWidth, bool bNeedPrint, string strFormText)
        {
            dgGrid.Con = dBAccess.Con;
            dgGrid.ColumnWidth = strColWidth;
            dgGrid.DataTable = dtData;
            this.Text = strFormText;
        }

        public void ShowData(DBAccess dBAccess, string strSql)
        {
            ShowData(dBAccess, strSql, string.Empty, false);
        }
        public void ShowData(DBAccess dBAccess, string strSql, string strColWidth, bool bNeedPrint)
        {
            dgGrid.Con = dBAccess.Con;
            dgGrid.TableName = this.TableName;
            dgGrid.ColumnWidth = strColWidth;
            dgGrid.GridHeight = this.Height;
            dgGrid.Sql = strSql;
        }
        #endregion

        #region ***Form Events
        private void frmInquiry_Load(object sender, EventArgs e)
        {
            string strSql = string.Empty;
            string strColWidth = string.Empty;
            dBAccess = new DBAccess(false, false);

            if (this.CurrentMenuInfo.strMenuName.Trim() != string.Empty)
                this.Text = this.CurrentMenuInfo.strMenuName;
            else
                this.Text = DataFunctions.GetFieldValue(dBAccess, "mTableDict", "mtnModuleTitle", "Tablename='" + m_strTableName + "'");

            strColWidth = DataFunctions.GetGridColumnWidthString(this.Name,this.TableName, this.CurrentMenuInfo.iParameter, SysVar.UserName, this.Name + "." + this.dgGrid.Name);
            strSql = WP.Commons.BaseFunctions.GetLookUpSQL(this.TableName, this.CurrentMenuInfo.iParameter);
            //strSql = DataFunctions.GetFieldValue(dBAccess, "mTableDict", "SqlUseList", "TableName = '" + m_strTableName + "'");

            this.btnTop.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.btnPrev.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.btnNext.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.btnBottom.DisplayStyle = ToolStripItemDisplayStyle.Image;

            ShowData(dBAccess, strSql, strColWidth, false);
        }
        private void frmInquiry_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            DataFunctions.SetGridColumnWidthString(this.Name, this.TableName, this.CurrentMenuInfo.iParameter, SysVar.UserName, this.dgGrid);
        }

        private void frmInquiry_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
        {
            dBAccess.CloseCon();
        }
        private void dgGrid_DefineColumn(object sender, EventArgs e)
        {
            frmSelectField f = new frmSelectField();
            string strSql = f.GetSelectSql(dgGrid.Sql, this.TableName, this.CurrentMenuInfo);
            if (strSql == "") return;
            dgGrid.Sql = strSql;
        }

        private void btnTop_Click(object sender, EventArgs e)
        {
            this.dgGrid.PressTop();
        }
        private void btnPrevPage_Click(object sender, EventArgs e)
        {
            this.dgGrid.PressPageUp();
        }
        private void btnNextPage_Click(object sender, EventArgs e)
        {
            this.dgGrid.PressPageDown();
        }
        private void btnBottom_Click(object sender, EventArgs e)
        {
            this.dgGrid.PressButtom();
        }

        private void btnInquiry_Click(object sender, EventArgs e)
        {
            this.dgGrid.PressTop();
        }
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion

    }
}